home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / win / whttpd14.zip / SUPPORT / SIGHTTPD / SIGHTTPD.C next >
C/C++ Source or Header  |  1994-06-04  |  4KB  |  133 lines

  1. //tabs=4
  2. //
  3. //        ==========
  4. //        SIGHTTPD.C
  5. //      ==========
  6. //
  7. // This is the C source for a DLL that finds the Windows Web Server httpd
  8. // and sends it a message that signals it to cycle its logfile(s). It was
  9. // written to be used from the Visual Basic usage analyzer VBUSAGE.
  10. //
  11. // WARNING: The message code (WM_USER+13) is hardwired.
  12. //
  13. // History:
  14. //    Who               When        What
  15. //    ----------------- ---------   --------------------------------------
  16. //    Robert B. Denny   04-Jun-94   Created - First internal test release
  17. //
  18.  
  19. #include <windows.h>
  20. #define WEP_NEEDEDoff
  21.  
  22. HINSTANCE _hInst;                // Instance handle of this DLL
  23. HWND hTheWindow;                // Used by WindCatcher() during enumeration
  24.  
  25. BOOL CALLBACK WindCatcher(HWND hWnd, LPARAM lparam);
  26.  
  27. //--------------------------------------------------------------------------
  28. //
  29. // LibMain() - DLL entry function
  30. //
  31. // Called only once, when the DLL is first loaded. Nothing to do here.
  32. //
  33. //--------------------------------------------------------------------------
  34. #pragma argsused
  35. int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg,
  36.                                 WORD cbHeapSize, LPSTR lpszCmdLine)
  37. {
  38.  
  39.     if(cbHeapSize !=0 )
  40.         UnlockData(0);                  // Unlock data segment
  41.     _hInst = hInstance;                  // Save our instance handle
  42.  
  43.     return(1);
  44. }
  45.  
  46. //--------------------------------------------------------------------------
  47. //
  48. // WEP() - DLL termination function
  49. //
  50. // Notes:  In Borland C++, we don't need a WEP function, BC4 provides
  51. //         its own, and calls ours, if present. Here we just disable
  52. //         the code...
  53. //
  54. // WARNING: Do not export WEP in the module definition file if using
  55. //          BC4. It is not needed.
  56. //
  57. //--------------------------------------------------------------------------
  58. #if defined (WEP_NEEDED)
  59. #pragma argsused
  60. int CALLBACK WEP(int nParamater)
  61. {
  62.     return(0);
  63. }
  64. #endif
  65.  
  66.  
  67.  
  68. //--------------------------------------------------------------------------
  69. //
  70. // SigHTTPD() - Signal Windows httpd to cycle log(s).
  71. //
  72. // Enumerates windows looking for one whose name starts with 'httpd'. Once
  73. // found, it posts a (WM_USER + 13) message to that window. The wParam of
  74. // the message tells which logfiles to cycle (mask):
  75. //
  76. //    wParam = 1        Cycle access log
  77. //    wParam = 2        Cycle Error log
  78. //    wParam = 3        Cycle both logs
  79. //
  80. // Returns non-zero (-1, true) if successful, else 0 (false)
  81. //--------------------------------------------------------------------------
  82. int FAR PASCAL SigHTTPD(BOOL fAcc, BOOL fErr)
  83. {
  84.     FARPROC lpfnEnumWinCB;            // Thunk for enum callback
  85.  
  86.     hTheWindow = NULL;                // Assume failure
  87.  
  88.     lpfnEnumWinCB = MakeProcInstance((FARPROC)WindCatcher, _hInst);
  89.     EnumWindows(lpfnEnumWinCB, NULL);
  90.     FreeProcInstance(lpfnEnumWinCB);
  91.  
  92.     if(hTheWindow != NULL)            // If we found an httpd running
  93.     {
  94.         WORD mask = 0;
  95.  
  96.         if(fAcc) mask |= 1;            // Make the mask
  97.         if(fErr) mask |= 2;
  98.         //
  99.         // NOTE: This is hard-coded for httpd V1.2b8.
  100.         //
  101.         return(PostMessage(hTheWindow, (WM_USER + 13), mask, 0));
  102.     }
  103.     return(0);
  104. }
  105.  
  106.  
  107. //------------------------------------------------------------------------
  108. //
  109. // WindCatcher() - Callback function for EnumTaskWindows(). Passes
  110. //                 back a copy of the next window handle.
  111. //
  112. //------------------------------------------------------------------------
  113. #define BUF_LEN 64
  114. #pragma argsused
  115. BOOL CALLBACK WindCatcher (HWND hWnd, LPARAM lparam)
  116. {
  117.     char buf[BUF_LEN+1];
  118.     static const char *tgtName = "httpd";
  119.     register int i;
  120.  
  121.     GetWindowText(hWnd, (LPSTR)buf, BUF_LEN);    // Get name
  122.     for(i=0; i < 5; i++)                        // Avoid huge C library
  123.         if(buf[i] != tgtName[i])
  124.             break;
  125.     if(i == 5)
  126.     {                                            // Found it
  127.         hTheWindow = hWnd;
  128.         return(FALSE);
  129.     }
  130.     return(TRUE);                                // Keep going
  131. }
  132.  
  133.